﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace KongMing.ORM.EFCore
{
    public class 分组查询
    {
        public static void Go()
        {
            using (var db = new EFDBContext())
            {
                //1.lambda
                var group_lambda_list = db.Book.GroupBy(x => new {x.Author, x.InPrice }).Select(x => x.Key).ToList();
               
                //2.Linq
                var group_linq_list = (from x in db.Book
                                       group x by new { x.Author, x.InPrice } into g
                                       select new { g.Key.Author, g.Key.InPrice }).ToList();
               
                //3.生成字典
                Dictionary<string, decimal> group_lambda_dic = db.Book.GroupBy(x => new { x.Author, x.InPrice })
                    .Select(x => x.Key).ToDictionary(x => x.Author, x => x.InPrice);

            }    
        }


    }
}
